/*
	审批流管理
*/
package approval

import (
	"data/config"
	"data/view/auth"
	"data/view/auth/auth_const"
	"data/view/common"
	"data/view/team"
	"data/view/user"
	"fmt"
	"public/message"
	"public/mysqldb"
	"public/tools"
	"strings"
	"time"

	"github.com/ant0ine/go-json-rest/rest"
)

//添加审批流类型
func OnAddType(w rest.ResponseWriter, r *rest.Request) {
	var req Req_addType
	tools.GetRequestJsonObj(r, &req)

	//参数检测
	if !tools.CheckParam(req.Access_token, req.Type_name, req.Url) {
		w.WriteJson(message.GetErrorMsg(message.ParameterInvalid, req))
		return
	}

	var db mysqldb.MySqlDB
	defer db.OnDestoryDB()
	orm := db.OnGetDBOrm(config.GetDbUrl())

	var info Approval_type_tbl
	info.Name = req.Type_name
	info.Url = req.Url
	orm.Save(&info)
	if len(req.Template_name) > 0 {
		var template Approval_list_tbl
		template.Type_name = req.Type_name
		template.Name = req.Template_name
		template.Url = req.Template_url
		template.Is_vaild = 1
		orm.Save(&template)
	}
	mp := make(map[string]string)
	mp["type_name"] = req.Type_name
	mp["url"] = req.Url
	mp["template_name"] = req.Template_name
	mp["template_url"] = req.Template_url
	msg := message.GetSuccessMsg()
	msg.Data = mp
	w.WriteJson(msg)
}

//获取审批流类型数组
func OnGetType(w rest.ResponseWriter, r *rest.Request) {
	var req Req_getType
	tools.GetRequestJsonObj(r, &req)

	//参数检测
	if !tools.CheckParam(req.Access_token) {
		w.WriteJson(message.GetErrorMsg(message.ParameterInvalid, req))
		return
	}

	var db mysqldb.MySqlDB
	defer db.OnDestoryDB()
	orm := db.OnGetDBOrm(config.GetDbUrl())

	var info []Approval_type_tbl

	orm.Find(&info)

	msg := message.GetSuccessMsg()
	msg.Data = info
	w.WriteJson(msg)
}

//删除审批流类型
func OnDeleteType(w rest.ResponseWriter, r *rest.Request) {
	var req Req_deleteType
	tools.GetRequestJsonObj(r, &req)

	//参数检测
	if !tools.CheckParam(req.Access_token, req.Name) {
		w.WriteJson(message.GetErrorMsg(message.ParameterInvalid, req))
		return
	}

	var db mysqldb.MySqlDB
	defer db.OnDestoryDB()
	orm := db.OnGetDBOrm(config.GetDbUrl())

	var info []Approval_list_tbl
	orm.Where("type_name = ?", req.Name).Find(&info)
	if len(info) > 0 {
		w.WriteJson(message.GetErrorMsg(message.NotVaildError, "只允许删除空类型"))
		return
	}

	orm.Delete(Approval_type_tbl{}, "name = ?", req.Name)
	w.WriteJson(message.GetSuccessMsg())
}

//编辑审批模板
func UpdateTemplate(w rest.ResponseWriter, r *rest.Request) {
	var req UpdateTemplateParam
	tools.GetRequestJsonObj(r, &req)

	//参数检测
	if !tools.CheckParam(req.Access_token, req.Type_name, req.Name) {
		w.WriteJson(message.GetErrorMsg(message.ParameterInvalid, req))
		return
	}
	//验证token，并获取用户名
	username, _, bfind := user.GetUserFromToken(req.Access_token)
	if !bfind {
		w.WriteJson(message.GetErrorMsg(message.TokenFailure))
		return
	}
	var db mysqldb.MySqlDB
	defer db.OnDestoryDB()
	orm := db.OnGetDBOrm(config.GetDbUrl())

	//判断是否存在
	var a_list Approval_list_tbl
	orm.Where("name = ? and type_name = ?", req.Name, req.Type_name).Find(&a_list)
	if a_list.Id == 0 {
		w.WriteJson(message.GetErrorMsg(message.NotFindError))
		return
	}
	//判断能否修改为无效
	if req.Is_vaild == -1 {
		var event []Approval_event_tbl
		orm.Where("ref_id = ? and is_vaild = 0 and status = 3", a_list.Id).Find(&event)
		if len(event) > 0 {
			w.WriteJson(message.GetErrorMsg(message.InValidOp, "存在正在审批"))
			return
		}
		//删除
		orm.Delete(Approval_event_tbl{}, "ref_id = ? and is_vaild = 0 and status = 3", a_list.Id)
	}
	var info Approval_list_tbl
	if a_list.Flag == common.APPROVAL_NORMAL { //通用审批
		info.Widget_info = req.Widget_info
	}
	if len(req.Approvers) > 0 {
		info.Approvers = fmt.Sprintf("%s", req.Approvers[0])
		for i := 1; i < len(req.Approvers); i++ {
			info.Approvers += common.SPLIT + fmt.Sprintf("%s", req.Approvers[i])
		}
	}

	if len(req.Copyers) > 0 {
		info.Copyers = fmt.Sprintf("%s", req.Copyers[0])
		for i := 1; i < len(req.Copyers); i++ {
			info.Copyers += common.SPLIT + fmt.Sprintf("%s", req.Copyers[i])
		}
	}
	info.Url = req.Url
	info.Attach = req.Attach
	info.Update_time = time.Now()
	info.Operator = username
	info.Is_vaild = req.Is_vaild
	err := orm.Table("approval_list_tbl").Where("name = ? and type_name = ?", req.Name, req.Type_name).
		Updates(&info).Error
	if err != nil {
		w.WriteJson(message.GetErrorMsg(message.UnknownError))
		return
	}
	msg := message.GetSuccessMsg()
	w.WriteJson(msg)
}

//获取审批模板
func GetAllTemplate(w rest.ResponseWriter, r *rest.Request) {
	var req UpdateTemplateParam
	tools.GetRequestJsonObj(r, &req)

	//参数检测
	if !tools.CheckParam(req.Access_token) {
		w.WriteJson(message.GetErrorMsg(message.ParameterInvalid, req))
		return
	}
	//验证token，并获取用户名
	_, _, bfind := user.GetUserFromToken(req.Access_token)
	if !bfind {
		w.WriteJson(message.GetErrorMsg(message.TokenFailure))
		return
	}
	var db mysqldb.MySqlDB
	defer db.OnDestoryDB()
	orm := db.OnGetDBOrm(config.GetDbUrl())

	var result []Template_s_info
	var types []Approval_type_tbl
	orm.Find(&types)
	if len(types) > 0 {
		for _, v := range types {
			var tmp Template_s_info
			tmp.Name = v.Name
			tmp.Url = v.Url
			var ss []Template_s
			orm.Table("approval_list_tbl").Where("type_name = ?", v.Name).Find(&ss)
			tmp.List = ss
			result = append(result, tmp)
		}
	}
	msg := message.GetSuccessMsg()
	msg.Data = result
	w.WriteJson(msg)
}

//获取审批模板详情
func GetTemplateDetail(w rest.ResponseWriter, r *rest.Request) {
	var req UpdateTemplateParam
	tools.GetRequestJsonObj(r, &req)

	//参数检测
	if !tools.CheckParam(req.Access_token, req.Name, req.Type_name) {
		w.WriteJson(message.GetErrorMsg(message.ParameterInvalid, req))
		return
	}

	//验证token，并获取用户名
	username, _, bfind := user.GetUserFromToken(req.Access_token)
	if !bfind {
		w.WriteJson(message.GetErrorMsg(message.TokenFailure))
		return
	}
	u, bb := user.GetUserDetail(username)
	if !bb {
		w.WriteJson(message.GetErrorMsg(message.UserNotExisted))
		return
	}
	//权限检验
	b := auth.CheckRoleAuth(u.Business_role, auth_const.M_5, auth_const.L_A, auth_const.L_B, auth_const.L_C)
	if !b {
		w.WriteJson(message.GetErrorMsg(message.UserMenuNotExisted))
		return
	}

	var db mysqldb.MySqlDB
	defer db.OnDestoryDB()
	orm := db.OnGetDBOrm(config.GetDbUrl())

	var tmp Approval_list_tbl
	var result Approval_list_return
	orm.Where("name = ? and type_name = ?", req.Name, req.Type_name).Find(&tmp)
	if tmp.Id > 0 {
		var approvers, copyers []User_info_tmp
		tmp1 := strings.Split(tmp.Approvers, common.SPLIT)
		tmp2 := strings.Split(tmp.Copyers, common.SPLIT)
		//获取审批人和抄送人
		approvers, copyers = GetApproversAndCopers(tmp1, tmp2, username)
		result.Approvers = approvers
		result.Attach = tmp.Attach
		result.Copyers = copyers
		result.Update_time = tmp.Update_time
		result.Name = tmp.Name
		result.Operator = tmp.Operator
		result.Type_name = tmp.Type_name
		result.Url = tmp.Url
		result.Is_vaild = tmp.Is_vaild
		// var ss Widget_all
		// json.Unmarshal([]byte(tmp.Widget_info), &ss)
		// result.Widget_Group = ss.Group
		// result.Widget_info = ss.Normal
		result.Widget_info = tmp.Widget_info
		result.Flag = tmp.Flag
	}
	msg := message.GetSuccessMsg()
	msg.Data = result
	w.WriteJson(msg)
}

//提交审批
func Submit(w rest.ResponseWriter, r *rest.Request) {
	var req SubmitParam
	tools.GetRequestJsonObj(r, &req)

	//参数检测
	if !tools.CheckParam(req.Access_token, req.Name, req.Type_name) {
		w.WriteJson(message.GetErrorMsg(message.ParameterInvalid, req))
		return
	}
	//验证token，并获取用户名
	username, _, bfind := user.GetUserFromToken(req.Access_token)
	if !bfind {
		w.WriteJson(message.GetErrorMsg(message.TokenFailure))
		return
	}
	_, bb := user.GetUserDetail(username)
	if !bb {
		w.WriteJson(message.GetErrorMsg(message.UserNotExisted))
		return
	}
	var db mysqldb.MySqlDB
	defer db.OnDestoryDB()
	orm := db.OnGetDBOrm(config.GetDbUrl())

	//验证审批是否有效
	var approval Approval_list_tbl
	orm.Where("name = ? and type_name = ? and is_vaild = 1", req.Name, req.Type_name).Find(&approval)
	if approval.Id == 0 {
		w.WriteJson(message.GetErrorMsg(message.NotFindError))
		return
	}
	apply_no := common.CreateUnique("")
	var event Approval_event_tbl
	event.Ref_id = int(approval.Id)
	// bb, _ := json.Marshal(req.Content)
	//string(bb)
	event.Content = req.Content
	event.Apply_time = time.Now()
	event.Apply_no = apply_no
	event.Applicant = username
	event.Status = common.APPROVAL_ING
	err := orm.Create(&event).Error
	if err != nil {
		w.WriteJson(message.GetErrorMsg(message.UnknownError))
		return
	}
	approvers := strings.Split(approval.Approvers, common.SPLIT) //审批人
	copers := strings.Split(approval.Copyers, common.SPLIT)      //抄送人

	var parent string //团队长
	if len(team.OnGetTeamBasicInfoByUser(username).Leader) > 0 {
		parent = team.OnGetTeamBasicInfoByUser(username).Leader[0].User
	}

	//创建审批人和抄送人列表
	b := CreateApproversAndCopers(approvers, copers, username, apply_no, parent, int(approval.Id))
	if !b {
		w.WriteJson(message.GetErrorMsg(message.UnknownError))
		return
	}
	//TODO
	//推送第一审批人、全部抄送人
	//TODO
	msg := message.GetSuccessMsg()
	msg.Data = apply_no
	w.WriteJson(msg)
}

//撤销审批
func Cancel(w rest.ResponseWriter, r *rest.Request) {
	var req CancelParam
	tools.GetRequestJsonObj(r, &req)

	//参数检测
	if !tools.CheckParam(req.Access_token, req.Apply_no) {
		w.WriteJson(message.GetErrorMsg(message.ParameterInvalid, req))
		return
	}
	//验证token，并获取用户名
	username, _, bfind := user.GetUserFromToken(req.Access_token)
	if !bfind {
		w.WriteJson(message.GetErrorMsg(message.TokenFailure))
		return
	}
	var db mysqldb.MySqlDB
	defer db.OnDestoryDB()
	orm := db.OnGetDBOrm(config.GetDbUrl())

	//验证审批是否有效
	var event Approval_event_tbl
	orm.Where("apply_no = ? and applicant = ?", req.Apply_no, username).Find(&event)
	if event.Id == 0 {
		w.WriteJson(message.GetErrorMsg(message.NotFindError))
		return
	}
	//验证是否已有审批
	var results []Approval_result_tbl
	orm.Where("apply_no = ? and result != 0", req.Apply_no).Find(&results)
	if len(results) > 0 {
		w.WriteJson(message.GetErrorMsg(message.InValidOp, "已有审批"))
		return
	}
	mp := map[string]interface{}{"is_vaild": -1, "attach": req.Attach}
	err := orm.Table("approval_event_tbl").Where("apply_no = ?", req.Apply_no).Updates(mp).Error
	//删除审批结果
	err = orm.Table("approval_result_tbl").Delete(Approval_result_tbl{}, "apply_no = ?", req.Apply_no).Error
	if err != nil {
		w.WriteJson(message.GetErrorMsg(message.UnknownError))
		return
	}
	msg := message.GetSuccessMsg()
	w.WriteJson(msg)
}

//我发起的审批
func GetMineSubmit(w rest.ResponseWriter, r *rest.Request) {
	var req GetMineSubmitParam
	tools.GetRequestJsonObj(r, &req)

	//参数检测
	if !tools.CheckParam(req.Access_token) {
		w.WriteJson(message.GetErrorMsg(message.ParameterInvalid, req))
		return
	}
	//验证token，并获取用户名
	username, _, bfind := user.GetUserFromToken(req.Access_token)
	if !bfind {
		w.WriteJson(message.GetErrorMsg(message.TokenFailure))
		return
	}
	var db mysqldb.MySqlDB
	defer db.OnDestoryDB()
	orm := db.OnGetDBOrm(config.GetDbUrl())

	var tmp, event []Approval_event_view
	sql := orm.Table("Approval_event_tbl as a ").Select("l.name,l.type_name,l.flag,a.*").Joins("join Approval_list_tbl as l on a.ref_id = l.id").
		Where("applicant = ?", username)
	if len(req.Search) > 0 {
		sql = sql.Or("apply_no = ?", req.Search).Or("content like ?", "%"+req.Search+"%")
	}
	if len(req.Name) > 0 {
		sql = sql.Where("name = ?", req.Name)
	}
	if req.Status != 0 {
		if req.Status == common.APPROVAL_FAIL { //审批未通过
			sql = sql.Where("status = ?", common.APPROVAL_FAIL)
		} else if req.Status == common.APPROVAL_SUCCESS { //审批已通过
			sql = sql.Where("status = ?", common.APPROVAL_SUCCESS)
		} else if req.Status == common.APPROVAL_ING { //审批中
			sql = sql.Where("status = ?", common.APPROVAL_ING)
		} else if req.Status == common.APPROVAL_REVOKE { //已撤销
			sql = sql.Where("is_vaild = ?", -1)
		}
	}
	sql.Find(&tmp)

	if len(tmp) > 0 {
		for _, v := range tmp {
			var t Approval_event_view
			t.Applicant = v.Applicant
			t.Apply_no = v.Apply_no
			t.Attach = v.Attach
			t.Apply_time = v.Apply_time
			t.Is_vaild = v.Is_vaild
			t.Name = v.Name
			t.Status = v.Status
			t.Type_name = v.Type_name
			// var ss []Widget_simple_info
			// json.Unmarshal([]byte(v.Content_str), &ss)
			t.Content = v.Content_str
			t.Flag = v.Flag
			event = append(event, t)
		}
	}
	msg := message.GetSuccessMsg()
	msg.Data = event
	w.WriteJson(msg)
}

//获取审批详情
func GetDetail(w rest.ResponseWriter, r *rest.Request) {
	var req CancelParam
	tools.GetRequestJsonObj(r, &req)

	//参数检测
	if !tools.CheckParam(req.Access_token, req.Apply_no) {
		w.WriteJson(message.GetErrorMsg(message.ParameterInvalid, req))
		return
	}
	// 验证token，并获取用户名
	_, _, bfind := user.GetUserFromToken(req.Access_token)
	if !bfind {
		w.WriteJson(message.GetErrorMsg(message.TokenFailure))
		return
	}
	var db mysqldb.MySqlDB
	defer db.OnDestoryDB()
	orm := db.OnGetDBOrm(config.GetDbUrl())

	var result Approval_event_all_view
	orm.Table("Approval_event_tbl as a ").Select("l.name,l.type_name,l.copyers,l.flag,a.*").
		Joins("join Approval_list_tbl as l on a.ref_id = l.id").
		Where("apply_no = ?", req.Apply_no).Find(&result)

	result.Content = result.Content_str
	tmp := strings.Split(result.Copyers_str, common.SPLIT)

	//获取抄送人和审批结果
	result.Copyers, result.Approval_result = GetCopersAndResult(tmp, result.Applicant, req.Apply_no)
	msg := message.GetSuccessMsg()
	msg.Data = result
	w.WriteJson(msg)
}

//我审批的
func GetMineApproval(w rest.ResponseWriter, r *rest.Request) {
	var req GetMineSubmitParam
	tools.GetRequestJsonObj(r, &req)

	//参数检测
	if !tools.CheckParam(req.Access_token) || req.Status == 0 {
		w.WriteJson(message.GetErrorMsg(message.ParameterInvalid, req))
		return
	}
	//验证token，并获取用户名
	username, _, bfind := user.GetUserFromToken(req.Access_token)
	if !bfind {
		w.WriteJson(message.GetErrorMsg(message.TokenFailure))
		return
	}
	var db mysqldb.MySqlDB
	defer db.OnDestoryDB()
	orm := db.OnGetDBOrm(config.GetDbUrl())

	var tmp, event []Approval_event_view
	sql := orm.Table("Approval_event_tbl as a ").Select("l.name,l.type_name,l.flag,a.*").Joins("join Approval_list_tbl as l on a.ref_id = l.id")

	var rets []Approval_result_tbl
	var apply_nos []string
	if req.Status == 1 { //待我审批
		orm.Where("approver = ? and is_current = 1", username).Find(&rets)
		if len(rets) > 0 {
			for _, v := range rets {
				apply_nos = append(apply_nos, v.Apply_no)
			}
		}
		sql = sql.Where("apply_no in (?)", apply_nos)
	} else if req.Status == 2 { //我已审批
		orm.Where("approver = ? and result != 0", username).Find(&rets)
		if len(rets) > 0 {
			for _, v := range rets {
				apply_nos = append(apply_nos, v.Apply_no)
			}
		}
		sql = sql.Where("apply_no in (?)", apply_nos)
	} else {
		w.WriteJson(message.GetErrorMsg(message.ParameterInvalid))
		return
	}
	if len(req.Search) > 0 {
		sql = sql.Or("apply_no = ?", req.Search).Or("content like ?", "%"+req.Search+"%")
	}
	if len(req.Name) > 0 {
		sql = sql.Where("name = ?", req.Name)
	}
	sql.Find(&tmp)

	if len(tmp) > 0 {
		for _, v := range tmp {
			var t Approval_event_view
			t.Applicant = v.Applicant
			t.Apply_no = v.Apply_no
			t.Apply_time = v.Apply_time
			t.Attach = v.Attach
			t.Is_vaild = v.Is_vaild
			t.Name = v.Name
			t.Status = v.Status
			t.Type_name = v.Type_name
			// var ss []Widget_simple_info
			// json.Unmarshal([]byte(v.Content_str), &ss)
			t.Content = v.Content_str
			t.Flag = v.Flag
			event = append(event, t)
		}
	}
	msg := message.GetSuccessMsg()
	msg.Data = event
	w.WriteJson(msg)

}

//进行审批
func Deal(w rest.ResponseWriter, r *rest.Request) {
	var req DealParam
	tools.GetRequestJsonObj(r, &req)

	//参数检测
	if !tools.CheckParam(req.Access_token, req.Apply_no) || req.Result == 0 {
		w.WriteJson(message.GetErrorMsg(message.ParameterInvalid, req))
		return
	}
	//验证token，并获取用户名
	username, _, bfind := user.GetUserFromToken(req.Access_token)
	if !bfind {
		w.WriteJson(message.GetErrorMsg(message.TokenFailure))
		return
	}
	var db mysqldb.MySqlDB
	defer db.OnDestoryDB()
	orm := db.OnGetDBOrm(config.GetDbUrl())

	//判断能否审批
	var result Approval_result_tbl
	orm.Where("approver = ? and is_current = 1 and apply_no = ?", username, req.Apply_no).Find(&result)
	if result.Id == 0 {
		w.WriteJson(message.GetErrorMsg(message.InValidOp))
		return
	}
	//进行审批
	mp := map[string]interface{}{"approval_time": time.Now(), "result": req.Result, "comment": req.Comment, "is_current": 0}
	err := orm.Table("approval_result_tbl").Where("approver = ? and apply_no = ?", username, req.Apply_no).Updates(mp).Error
	if err != nil {
		w.WriteJson(message.GetErrorMsg(message.UnknownError))
		return
	}
	var event Approval_event_tbl
	var atype Approval_list_tbl
	orm.Where("apply_no = ?", req.Apply_no).Find(&event)
	orm.First(&atype, event.Ref_id)
	b, next := getNextApprover(username, atype.Approvers)

	var result_status int = common.APPROVAL_ING //审批结果 默认审批中

	if b { //审批结束
		if req.Result == -1 { //审批未通过
			result_status = common.APPROVAL_FAIL
			orm.Table("approval_event_tbl").Where("apply_no = ?", req.Apply_no).Update("status", common.APPROVAL_FAIL)
		}
		if req.Result == 1 { //审批通过
			result_status = common.APPROVAL_SUCCESS
			orm.Table("approval_event_tbl").Where("apply_no = ?", req.Apply_no).Update("status", common.APPROVAL_SUCCESS)
		}
	} else {
		if req.Result == -1 { //审批未通过
			result_status = common.APPROVAL_FAIL
			orm.Table("approval_event_tbl").Where("apply_no = ?", req.Apply_no).Update("status", common.APPROVAL_FAIL)
		}
		if req.Result == 1 { //审批通过
			orm.Table("approval_result_tbl").Where("approver = ? and apply_no = ?", next, req.Apply_no).Update("is_current", 1)
			//推送下一审批人
			//TODO
		}
	}
	//TODO 通知申请人
	msg := message.GetSuccessMsg()
	msg.Data = result_status
	w.WriteJson(msg)
}

//抄送我的
func GetMineCopy(w rest.ResponseWriter, r *rest.Request) {
	var req GetMineSubmitParam
	tools.GetRequestJsonObj(r, &req)

	//参数检测
	if !tools.CheckParam(req.Access_token) {
		w.WriteJson(message.GetErrorMsg(message.ParameterInvalid, req))
		return
	}
	//验证token，并获取用户名
	username, _, bfind := user.GetUserFromToken(req.Access_token)
	if !bfind {
		w.WriteJson(message.GetErrorMsg(message.TokenFailure))
		return
	}
	var db mysqldb.MySqlDB
	defer db.OnDestoryDB()
	orm := db.OnGetDBOrm(config.GetDbUrl())

	var tmp, event []Approval_event_view
	sql := orm.Table("Approval_event_tbl as a ").Select("l.name,l.type_name,l.flag,a.*").Joins("join Approval_list_tbl as l on a.ref_id = l.id").
		Where("a.ref_id in (?)", getCopyerList(username))

	if len(req.Search) > 0 {
		sql = sql.Or("apply_no = ?", req.Search).Or("content like ?", "%"+req.Search+"%")
	}
	if len(req.Name) > 0 {
		sql = sql.Where("name = ?", req.Name)
	}
	if req.Status != 0 {
		if req.Status == common.APPROVAL_FAIL { //审批未通过
			sql = sql.Where("status = ?", common.APPROVAL_FAIL)
		} else if req.Status == common.APPROVAL_SUCCESS { //审批已通过
			sql = sql.Where("status = ?", common.APPROVAL_SUCCESS)
		} else if req.Status == common.APPROVAL_ING { //审批中
			sql = sql.Where("status = ?", common.APPROVAL_ING)
		} else if req.Status == common.APPROVAL_REVOKE { //已撤销
			sql = sql.Where("is_vaild = ?", -1)
		}
	}
	sql.Find(&tmp)

	if len(tmp) > 0 {
		for _, v := range tmp {
			var t Approval_event_view
			t.Applicant = v.Applicant
			t.Apply_no = v.Apply_no
			t.Apply_time = v.Apply_time
			t.Attach = v.Attach
			t.Is_vaild = v.Is_vaild
			t.Name = v.Name
			t.Status = v.Status
			t.Type_name = v.Type_name
			// var ss []Widget_simple_info
			// json.Unmarshal([]byte(v.Content_str), &ss)
			t.Content = v.Content_str
			t.Flag = v.Flag
			event = append(event, t)
		}
	}
	msg := message.GetSuccessMsg()
	msg.Data = event
	w.WriteJson(msg)
}
